﻿using FluentValidation;
using Microsoft.AspNetCore.Identity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Quickly.Identity.Services.Manage.Roles;

public record CreateRoleCommand(string Name);
public class CreateRoleCommandValidator : AbstractValidator<CreateRoleCommand>
{
    public CreateRoleCommandValidator()
    {
        RuleFor(x => x.Name).NotNull().NotEmpty().WithMessage("名称不能为空");
    }
}

public class CreateRole
{
    public static async Task<IdentityResult> ExecuteAsync(CreateRoleCommand command, RoleManager<AppRole> roleManager, CancellationToken cancellationToken)
    {
        var role = new AppRole(command.Name);
        var result = await roleManager.CreateAsync(role);
        return result;
    }
}
